<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="5">
        <div class="grid-content bg-purple">
          <el-autocomplete
            v-model="hotelCity"
            :fetch-suggestions="queryCitySearch"
            :trigger-on-focus="false"
            :highlight-first-item="true"
            placeholder="切换城市"
            @select="handleCitySelect"
            class="el-autocomplete"
          ></el-autocomplete>
        </div>
      </el-col>
      <el-col :span="9">
        <div class="grid-content bg-purple">
          <div class="block">
            <el-date-picker
              v-model="hotelDate"
              type="daterange"
              range-separator="-"
              start-placeholder="入住日期"
              end-placeholder="离店日期"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple"></div>
      </el-col>
      <el-col :span="3">
        <div class="grid-content bg-purple">
          <el-button type="primary">查看价格</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="14">
        <div class="grid-content bg-purple">
          <div class="areaaverage"></div>
        </div>
      </el-col>
      <el-col :span="10">
        <div class="grid-content bg-purple">
          <div class="map">
            <div id="container"></div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hotelCity: "",
      hotelDate: "",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() <= Date.now() - 8.64e7;
        },
      },
    };
  },
  mounted() {
    window.onLoad = function () {
      var map = new AMap.Map("container", {
        resizeEnable: true,
        zoom: 12,
        viewMode: "3D", //使用3D视图
      });
    };
    var url =
      "https://webapi.amap.com/maps?v=1.4.15&key=fa28993d6a8fbba3f2149428b3996f72&callback=onLoad";
    var jsapi = document.createElement("script");
    jsapi.charset = "utf-8";
    jsapi.src = url;
    document.head.appendChild(jsapi);
  },
  methods: {
    queryCitySearch(queryString, callback) {
      this.$axios({
        url: "/airs/city",
        params: {
          name: queryString,
        },
      }).then((res) => {
        console.log(res.data);
        const suggestions = res.data.data.map((city) => {
          return {
            value: city.name,
          };
        });
        callback(suggestions);
      });
    },
    handleCitySelect() {},
  },
};
</script>

<style lang="less" scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.areaaverage {
  height: 260px;
  background-color: red;
}
.map {
  height: 260px;
  #container {
    width: 390px;
    height: 100%;
  }
}
</style>